package com.cdc.http.http2;

import android.support.annotation.NonNull;

import java.io.IOException;
import java.io.OutputStream;
import java.util.concurrent.atomic.AtomicLong;

/**
 * Created by admin on 2018/3/26.
 */

public class CounterOutPutStream extends OutputStream {
    private AtomicLong mAtomicLong=new AtomicLong();

    public long get(){
        long  lo=mAtomicLong.get();

        return lo;
    }

    @Override
    public void write(int b) throws IOException {
        mAtomicLong.addAndGet(1);
    }

    public void write(long b) throws IOException {
        mAtomicLong.addAndGet(b);
    }

    @Override
    public void write(@NonNull byte[] b) throws IOException {
        super.write(b);
        mAtomicLong.addAndGet(b.length);
    }

    @Override
    public void write(@NonNull byte[] b, int off, int len) throws IOException {
        super.write(b, off, len);
        mAtomicLong.addAndGet(len);
    }

    @Override
    public void flush() throws IOException {
        super.flush();
    }

    @Override
    public void close() throws IOException {
        super.close();
    }
}
